using System;
using System.Collections.Generic;
using System.Text;
using System.Net;

namespace Coriander.Google.Services.Authentication
{
    /// <summary>
    /// 
    /// </summary>
    public class SaslPlain
    {
        /// <summary>
        /// Creates a token suitable for use with SASL PLAIN authentication
        /// </summary>
        /// <param name="credential"></param>
        /// <returns></returns>
        public static String GetSaslPlainAuth(NetworkCredential credential)
        {
            return GetSaslPlainAuth(credential.UserName, credential.Password);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public static String GetSaslPlainAuth(String username, String password)
        {
            return Convert.ToBase64String(Encoding.UTF8.GetBytes(
                "\0" + username + "\0" + password));
        }
    }
}
